




/*
'===============================================================================
'  TuanHuy.BL.ProjectsManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using TuanHuy.BLL;
using TuanHuy.DAL;
using TuanHuy.DAL.EntityClasses;
using TuanHuy.DAL.FactoryClasses;
using TuanHuy.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace TuanHuy.BLL
{
	public class ProjectsManagerBase : ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		
		public ProjectsManagerBase()
		{
			// Nothing for now.
		}
		
		/*public override string TableName()
        {
            return "Projects";
        }*/
		
		public ProjectsEntity Insert(ProjectsEntity _ProjectsEntity)
		{
			return Insert(_ProjectsEntity, "");
		}
		
		public ProjectsEntity Insert(ProjectsEntity _ProjectsEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_ProjectsEntity, true);
				ProjectsFields field = new ProjectsFields();
                //LogEntity(_ProjectsEntity, field, AcInsert, controlId);
			}
			return _ProjectsEntity;
		}

		
		public ProjectsEntity Insert(decimal ProjectId, DateTime CreateDate)
		{
			ProjectsEntity _ProjectsEntity = new ProjectsEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_ProjectsEntity.ProjectId = ProjectId;
				_ProjectsEntity.CreateDate = CreateDate;
				ProjectsFields field = new ProjectsFields();
                //LogEntity(_ProjectsEntity, field, AcInsert);
				adapter.SaveEntity(_ProjectsEntity, true);
			}
			return _ProjectsEntity;
		}

		/*public ProjectsEntity Insert(DateTime CreateDate)
		{
			ProjectsEntity _ProjectsEntity = new ProjectsEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_ProjectsEntity.CreateDate = CreateDate;
				adapter.SaveEntity(_ProjectsEntity, true);
				ProjectsFields field = new ProjectsFields();
                //LogEntity(_ProjectsEntity, field, AcInsert);
			}
			return _ProjectsEntity;
		}*/
		
		public bool Update(ProjectsEntity _ProjectsEntity)
        {
            return Update(_ProjectsEntity, "");
        }

		public bool Update(ProjectsEntity _ProjectsEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(ProjectsFields.ProjectId == _ProjectsEntity.ProjectId);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_ProjectsEntity, filter);
				toReturn = true;
				
				ProjectsFields field = new ProjectsFields();
                //LogEntity(_ProjectsEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(ProjectsEntity _ProjectsEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_ProjectsEntity, filter);
				toReturn = true;
				
				ProjectsFields field = new ProjectsFields();
                //LogEntity(_ProjectsEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(decimal ProjectId, DateTime CreateDate)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				ProjectsEntity _ProjectsEntity = new ProjectsEntity(ProjectId);
				if (adapter.FetchEntity(_ProjectsEntity))
				{
				
					_ProjectsEntity.CreateDate = CreateDate;
					adapter.SaveEntity(_ProjectsEntity, true);
					toReturn = true;
					
					ProjectsFields field = new ProjectsFields();
					//LogEntity(_ProjectsEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(decimal ProjectId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				ProjectsEntity _ProjectsEntity = new ProjectsEntity(ProjectId);
				if (adapter.FetchEntity(_ProjectsEntity))
				{
					adapter.DeleteEntity(_ProjectsEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("ProjectsEntity", null);
			}
		}
		
		
		public int DeleteByProjectId(decimal ProjectId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.ProjectId == ProjectId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("ProjectsEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCreateDate(DateTime CreateDate)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.CreateDate == CreateDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("ProjectsEntity", filter);
			}
			return toReturn;
		}
		

		
		public ProjectsEntity SelectOne(decimal ProjectId)
		{
			ProjectsEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				ProjectsEntity _ProjectsEntity = new ProjectsEntity(ProjectId);
				if (adapter.FetchEntity(_ProjectsEntity))
				{
					toReturn = _ProjectsEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _ProjectsCollection = new EntityCollection(new ProjectsEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_ProjectsCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<ProjectsEntity>
		public EntityCollection<ProjectsEntity> SelectAllLST()
		{
			EntityCollection<ProjectsEntity> _ProjectsCollection = new EntityCollection<ProjectsEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_ProjectsCollection, null, 0, null);
			}
			return _ProjectsCollection;
		}
		
		// Return EntityCollection<ProjectsEntity>
		public EntityCollection<ProjectsEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<ProjectsEntity> _ProjectsCollection = new EntityCollection<ProjectsEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_ProjectsCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _ProjectsCollection;
		}


		
		// Return EntityCollection<ProjectsEntity>
		public EntityCollection<ProjectsEntity> SelectByProjectIdLST(decimal ProjectId)
		{
			EntityCollection<ProjectsEntity> _ProjectsCollection = new EntityCollection<ProjectsEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.ProjectId == ProjectId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_ProjectsCollection, filter, 0, null);
			}
			return _ProjectsCollection;
		}
		
		// Return EntityCollection<ProjectsEntity>
		public EntityCollection<ProjectsEntity> SelectByProjectIdLST_Paged(decimal ProjectId, int PageNumber, int PageSize)
		{
			EntityCollection<ProjectsEntity> _ProjectsCollection = new EntityCollection<ProjectsEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.ProjectId == ProjectId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_ProjectsCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _ProjectsCollection;
		}
		
		// Return DataTable
		public DataTable SelectByProjectIdRDT(decimal ProjectId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _ProjectsCollection = new EntityCollection(new ProjectsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.ProjectId == ProjectId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_ProjectsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByProjectIdRDT_Paged(decimal ProjectId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _ProjectsCollection = new EntityCollection(new ProjectsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.ProjectId == ProjectId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_ProjectsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<ProjectsEntity>
		public EntityCollection<ProjectsEntity> SelectByCreateDateLST(DateTime CreateDate)
		{
			EntityCollection<ProjectsEntity> _ProjectsCollection = new EntityCollection<ProjectsEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.CreateDate == CreateDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_ProjectsCollection, filter, 0, null);
			}
			return _ProjectsCollection;
		}
		
		// Return EntityCollection<ProjectsEntity>
		public EntityCollection<ProjectsEntity> SelectByCreateDateLST_Paged(DateTime CreateDate, int PageNumber, int PageSize)
		{
			EntityCollection<ProjectsEntity> _ProjectsCollection = new EntityCollection<ProjectsEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.CreateDate == CreateDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_ProjectsCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _ProjectsCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCreateDateRDT(DateTime CreateDate)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _ProjectsCollection = new EntityCollection(new ProjectsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.CreateDate == CreateDate);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_ProjectsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByCreateDateRDT_Paged(DateTime CreateDate, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _ProjectsCollection = new EntityCollection(new ProjectsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(ProjectsFields.CreateDate == CreateDate);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_ProjectsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		

	}
}
